package Json;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import test.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description fastJson
 * @Author zhongzihao
 * @Date 2021/6/23 9:43 上午
 */
public class JsonTest {
    public static void main(String[] args) {
        test1();
        test2();
        test4();
    }
    public static void test1(){
        List<Student> students = new ArrayList<Student>();
        students.add(new Student("wade",12));
        students.add(new Student("we",23));
        students.add(new Student("wade"));
        String str = JSON.toJSONString(students);
        System.out.println(str);
    }

    public static void test2(){
        String str ="[{\"age\":12,\"name\":\"wade\",\"name1\":\"wade1\"},{\"age\":23,\"name\":\"we\"}]";
        List<Student> students = JSON.parseArray(str,Student.class);
        for (Student s:students
             ) {
            System.out.println(s.toString());
        }
    }
    public static void test3(){
        String str ="[{\"age\":12,\"name\":\"wade\"},{\"age\":23,\"name\":\"we\"}]";
        List<Map<String, Object>> maps = JSON.parseObject(str, new TypeReference<List<Map<String, Object>>>() {
        });

    }
    public static void test4(){
        String str ="[\"wade\",\"we\"]";
        List<String> maps = JSON.parseArray(str,String.class);
        System.err.println(JSON.toJSONString(maps));
        System.out.println(maps);
        for (Object o:maps
             ) {
            System.err.println(o);
        }
    }

//    public static void test05(){
//        String str = "[{"}]"
//    }
}
